<?php
ob_start();
require_once '../sub/init.php';
require_once 'chkUadm.php';
if(!CRMQX('crm_bbs_list'))exit(noauth());
require_once ZEAI.'m/div_left_so.php';
require_once ZEAI.'cache/udata.php';
require_once ZEAI.'cache/config_crm.php';
/****************************************SQL 开始*****************************************/
$SQL = " a.uid=b.id AND b.crm_flag<3 AND kind<>4 AND (b.flag=1 OR b.flag=-2) ";//AND b.admid>0
//门店+地区
$SQL .= getAgentSQL('b');
//超管可以按门店搜索
if(ifint($agentid) && CRM_ADM)$SQL .= " AND b.agentid=$agentid";
//我的客户
if($ifmy==1)$SQL .= " AND (b.admid=".$session_uid." OR b.hnid=".$session_uid." OR b.hnid2=".$session_uid." )";
//关键字搜索
$Skey  = trimhtml($Skey);
$Skey2 = trimhtml($Skey2);
$Skey3 = trimhtml($Skey3);
if (!empty($Skey)){
	if(ifmob($Skey)){
		$SQL .= " AND b.mob=".$Skey;	
	}elseif(ifint($Skey)){
		$SQL .= " AND b.id=".$Skey;	
	}else{
		$SQL .= " AND (( b.truename LIKE '%".$Skey."%' ) OR ( b.crm_ubz LIKE '%".$Skey."%' ) OR ( b.uname LIKE '%".$Skey."%' ) OR ( b.nickname LIKE '%".$Skey."%' ) OR ( b.nickname LIKE '%".urlencode($Skey)."%' )) ";
	}
}
if(ifint($Skey2)){
	$SQL .= " AND (a.admid=$Skey2) ";
}elseif(!empty($Skey2)){
	$SQL .= " AND (  a.admname LIKE '%".$Skey2."%' )";
}
if(!empty($Skey3))$SQL .= " AND (  a.content LIKE '%".$Skey3."%' )";
//跟进时间
if(!empty($sDATE1)){
	$sDATE1_ = strtotime($sDATE1.' 00:00:01');
	$SQL .= " AND ( a.addtime >= '$sDATE1_' )";
}
if(!empty($sDATE2)){
	$sDATE2_ = strtotime($sDATE2.' 23:59:59');
	$SQL .= " AND ( a.addtime <= '$sDATE2_' )";
}
//按客户等级
if(ifint($crm_ugrade))$SQL .= " AND b.crm_ugrade=$crm_ugrade";
//按分类
if(ifint($crm_ukind))$SQL  .= " AND b.crm_ukind=$crm_ukind";
//意向
if (ifint($intention))$SQL .= " AND a.intention = $intention ";
//跟进时间
switch ($addtime) {
	case 1:$SQL .= " AND (".ADDTIME." - a.addtime) > 604800 ";break;//一周未跟进
	case 2:$SQL .= " AND (".ADDTIME." - a.addtime) > 2592000 ";break;//一月未跟进
	case 3:$SQL .= " AND (".ADDTIME." - a.addtime) > 7948800 ";break;//三月未跟进
	case 4:$SQL .= " AND ( TO_DAYS(from_unixtime(a.addtime))-TO_DAYS(NOW()) = 0 )";break;//今天已跟进
	case 5:$SQL .= " AND ( TO_DAYS(from_unixtime(a.addtime))-TO_DAYS(NOW()) = -1 )";break;//昨天已跟进
}
//下次联系
switch ($nexttime) {
	case 1:$SQL .= " AND ( TO_DAYS(from_unixtime(a.nexttime))-TO_DAYS(NOW()) = 0 )";break;//今天需跟进
	case 2:$SQL .= " AND ( TO_DAYS(from_unixtime(a.nexttime))-TO_DAYS(NOW()) = 1 )";break;//明天需跟进
	case 3:$SQL .= " AND ( TO_DAYS(from_unixtime(a.nexttime))-TO_DAYS(NOW()) = 2 )";break;//后天需跟进
	case 4:$SQL .= " AND ( a.nexttime<".ADDTIME."  )";break;//过期
}
$sortSQL  = "  ORDER BY a.addtime DESC,a.id DESC ";

$SQLnew = ",(SELECT MAX(id) AS max_id,COUNT(id) AS gjnum FROM ".__TBL_CRM_BBS__." GROUP BY uid) N";$SQL .= " AND a.id=N.max_id ";
$rt = $db->query("SELECT a.*,b.sex,b.grade,b.nickname,b.photo_s,b.crm_ukind,b.crm_ugrade,b.crm_usjtime1,b.crm_usjtime2,N.gjnum FROM ".__TBL_CRM_BBS__." a,".__TBL_USER__." b".$SQLnew." WHERE ".$SQL.$sortSQL." LIMIT ".$_ADM['admLimit']);
$total = $db->num_rows($rt);

/*************************************  SQL结束 ********************************************/
$bbs_intentionARR = json_decode($_CRM['bbs_intention'],true);

//$t=trimhtml($t);
$nav='index';?>
<!doctype html><html><head><meta charset="utf-8">
<title><?php echo $_ADM['admSiteName']; ?></title>
<?php echo HEADMETA; ?>
<script src="<?php echo RES;?>www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/m.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<link href="<?php echo RES;?>m/css/m.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<?php require_once 'm_style.php';?>
<link href="css/m_adm.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<style>
.ZEAI_list{padding:100px 0 80px;width:92%;margin:0 auto}
.ZEAI_list dl{width:100%;margin:0 auto 12px auto;border-radius:8px;background-color:#fff;box-shadow:0 0 28px rgb(0 0 0 / 8%);position:relative;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;position:relative;<?php if ($ifgh==1){?>padding-bottom:20px<?php }?>}
.ZEAI_list dl .tbody{padding:0 10px;margin:0 auto 10px auto;line-height:40px;height:40px;border-bottom:#f5f5f5 1px solid;text-align:left;overflow:hidden}
.ZEAI_list dl .tbody img.photo_s{width:40px;height:40px;margin-top:7px;object-fit:cover;-webkit-object-fit:cover;border-radius:50%;vertical-align:middle}

.ZEAI_list dl .tbody b,.ZEAI_list dl .tbody font{display:inline-block;color:#000;font-weight:normal}
.ZEAI_list dl .tbody font{color:#999}
.ZEAI_list dl .tbody .rtitle{float:right;line-height:44px;position:relative}

.ZEAI_list dl dt,.ZEAI_list dl dd{float:left;display:block}
.ZEAI_list dl dt{width:90px;text-align:left;line-height:150%;padding-top:10px}

.timebox{width:60px;height:60px;margin-left:12px;padding:12px 0 0 0;background-color:rgba(<?php echo c16_rgb($_ADM['color']);?>,.08);border-radius:5px;text-align:center;color:<?php echo $_ADM['color'];?>;position:relative;font-size:12px;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;font-family:Arial, Helvetica, sans-serif}
.timebox b{font-size:18px;margin-right:2px;}
.timebox font{display:inline-block}
.timebox .zj{width:0;height:0;left:60px;top:20px;position:absolute;border-top:10px solid transparent;border-bottom:10px solid transparent;border-left:10px solid rgba(<?php echo c16_rgb($_ADM['color']);?>,.08)}

.addtimetips{width:85px;font-size:12px;text-align:center;margin-top:5px}

.ZEAI_list dl dd{width:-webkit-calc(100% - 90px);text-align:left;min-height:70px;font-size:12px;color:#999}
.ZEAI_list dl dd em{width:90%;font-size:13px;line-height:200%;color:#000;margin:5px 0 10px 0}
.ZEAI_list dl dd.CC .pathlist img{margin:0 5px 2px 2px;width:50px;height:50px;object-fit:cover;-webkit-object-fit:cover;border-radius:2px}
.ZEAI_list dl dd.CC{padding:0 0 40px;word-break:break-all;word-wrap:break-word;line-height:180%;position:relative;padding-top:20px}
.ZEAI_list dl dd.CC .delico,.ZEAI_list dl dd.CC .editico,.crm_vip_ukind{position:absolute;bottom:15px;font-size:14px;color:#999}
.ZEAI_list dl dd.CC .editico{right:48px}
.ZEAI_list dl dd.CC .delico{right:12px}
.ZEAI_list dl .crm_vip_ukind{left:10px;font-size:13px}
.ZEAI_list dl .crm_vip_ukind a{border:0}

.ZEAI_list dl dd.CC .gjlist{position:absolute;right:15px;top:9px}
</style>
<!--ifrmae up-->
<?php require_once ZEAI.'cache/config_up.php';?>
<script>var up2='<?php echo UP;?>',upMaxMB=<?php echo $_UP['upMaxMB']; ?>,maxnum=5,browser='<?php echo browser();?>',uid='',upurl='';
</script>
<script src="<?php echo RES;?>m/js/ZeaiUP.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<?php
if (is_weixin()){
	require_once ZEAI."api/weixin/jssdk.php";?>
	<script src="<?php echo RES;?>jweixin-1.2.0.js"></script>
	<script>
	wx.config({debug: false,
		appId: '<?php echo $signPackage["appId"];?>',
		timestamp: <?php echo $signPackage["timestamp"];?>,
		nonceStr: '<?php echo $signPackage["nonceStr"];?>',
		signature: '<?php echo $signPackage["signature"];?>',
		jsApiList: ['chooseImage','uploadImage','previewImage','hideMenuItems']
	});
	</script>
<?php }?>
<!--ifrmae up end-->
</head>
<body>
<?php
$searchA = "?qxflag=$qxflag&ifmy=$ifmy";
$mini_title='红娘服务';
$mini_class='top_mini4 ';
$mini_L = '<em onClick="zeai.openurl(\'m_crm.php\')"><i class="ico" >&#xeaca;</i><span></span></em>';
require_once ZEAI.'m/top_mini.php';?>
<a class="so" id="user_search"><i class="ico">&#xe66c;</i><span>筛选</span></a>
<div class="tabmenu tabmenu2 tabmenufix">
    <a href="m_crm_user_bbs.php<?php echo $searchA;?>" class="ed">跟进列表(<?php echo $total;?>)</a>
    <a href="m_qianxian_list.php<?php echo $searchA;?>">牵线列表</a>
</div>
<!--div_left_so-->
<div id="rangebox"></div>
<div class="div_left_so" id="user_so">
	<form action="<?php echo SELF;?>" method="get" name="www.yzlove.com" id="ZEAI_CN_FORM_ext">
    	<div class="form_uid">
            <input name="Skey" type="text" class="input" id="Skey" maxlength="20" value="<?php echo $Skey;?>" placeholder="客户UID/姓名/昵称/手机/备注" autocomplete="off">
            <button type="submit" class="ico">&#xe6c4;</button>
		</div>
    	<div class="form_uid">
            <input name="Skey2" type="text" class="input" id="Skey2" maxlength="20" value="<?php echo $Skey2;?>" placeholder="红娘姓名/ID" autocomplete="off">
            <button type="submit" class="ico">&#xe6c4;</button>
		</div>
    	<div class="form_uid">
            <input name="Skey3" type="text" class="input" id="Skey3" maxlength="20" value="<?php echo $Skey3;?>" placeholder="跟进内容" autocomplete="off">
            <button type="submit" class="ico">&#xe6c4;</button>
		</div>
       <?php
		$FT=json_decode(FT,true);
		if(CRM_ADM){
			$rt2=$db->query("SELECT id,title FROM ".__TBL_CRM_AGENT__." WHERE flag=1 ORDER BY px DESC,id DESC");
			$total2 = $db->num_rows($rt2);
			if ($total2 > 0) {
				for($j=0;$j<$total2;$j++) {
					$rows2 = $db->fetch_array($rt2,'name');
					if(!$rows2)break;
					$agentARR[] = array('i'=>$rows2['id'],'v'=>$rows2['title']);
				}
				div_left_so_out(array('tbody'=>'所属门店','t'=>'agentid','tv'=>$agentid,'subkind'=>2,'newarr'=>json_decode(encode_json($agentARR)),'show'=>'off','ulcls'=>' col3'));
			}
		}
		div_left_so_out(array('tbody'=>'筛选范围','t'=>'ifmy','tv'=>$ifmy,'subkind'=>2,'newarr'=>json_decode('[{"i":"1","v":"我的客户"}]'),'ulcls'=>' col3'));
		div_left_so_out(array('tbody'=>'跟进时间','t'=>'addtime','tv'=>$addtime,'subkind'=>2,'newarr'=>json_decode('[{"i":"1","v":"一周未跟进"},{"i":"2","v":"一月未跟进"},{"i":"3","v":"三月未跟进"},{"i":"4","v":"今天已跟进"},{"i":"5","v":"昨天已跟进"}]'),'ulcls'=>' col3'));
		div_left_so_out(array('tbody'=>'客户分类','t'=>'crm_ukind','tv'=>$crm_ukind,'subkind'=>2,'newarr'=>json_decode($_UDATA['crm_ukind']),'show'=>'off','ulcls'=>' col3'));
		div_left_so_out(array('tbody'=>'线下客户等级','t'=>'crm_ugrade','tv'=>$crm_ugrade,'subkind'=>2,'newarr'=>json_decode($_UDATA['crm_ugrade']),'show'=>'off','ulcls'=>' col2'));
		div_left_so_out(array('tbody'=>'售前意向','t'=>'intention','tv'=>$intention,'subkind'=>2,'newarr'=>json_decode($_CRM['bbs_intention']),'show'=>'off','ulcls'=>' col2'));
		div_left_so_out(array('tbody'=>'下次联系','t'=>'nexttime','tv'=>$nexttime,'subkind'=>2,'newarr'=>json_decode('[{"i":"1","v":"今天需跟进"},{"i":"2","v":"明天需跟进"},{"i":"3","v":"后天需跟进"},{"i":"4","v":"过期未跟进"}]'),'ulcls'=>' col3'));
		//默认值
		function range_str($F,$V) {
			if(empty($V))return '';
			global $_UDATA;
			$FARR=explode(',',$V);
			$F1=$FARR[0];$F2=$FARR[1];
			$F_UDATA=json_decode($_UDATA[$V],true);
			$F_str = mateset_out($F1,$F2,$F_UDATA['dw']);
			$F_str = str_replace("不限","",$F_str);
			return $F_str;
		}?>
        <script>div_left_so_init('user_so');user_search.onclick=function(){ZeaiM.div_left({obj:user_so,w:28});}</script>
        <div class="savebox"><button type="button" class="btn size3 reset" onClick="div_left_so_reset('user_so')">重置</button><button type="submit" class="btn size3 zeaibg ico">&#xe6c4; 确定</button></div>
    </form>
</div>
<!--div_left_so end-->
<form id="www_zeai_cn_FORM" class="ZEAI_list" method="get" action="<?php echo SELF; ?>">
	<?php
	if ($total <= 0 ) {
		echo "<div class='nodataico'><i class='ico'>&#xe608;</i>暂无信息<br><br><a class='aBAI' href='javascript:history.back(-1)'>返回上一步</a></div>";
	} else {
		$page_skin=2;$pagemode='mob';$pagesize=10;require_once ZEAI.'sub/page.php';
		for($i=1;$i<=$pagesize;$i++) {
			$rows = $db->fetch_array($rt,'name');if(!$rows) break;
            $id = $rows['id'];$uid = $rows['uid'];
            $nickname = trimhtml(dataIO($rows['nickname'],'out'));
            $sex     = $rows['sex'];
            $grade   = $rows['grade'];
            $addtime = $rows['addtime'];
            $addtime_ = YmdHis($addtime,'YmdHi');
            $photo_s = $rows['photo_s'];
            $content = dataIO($rows['content'],'out');
            $intention = intval($rows['intention']);
            $admid   = $rows['admid'];
            $admname = dataIO($rows['admname'],'out');
            $nexttime = $rows['nexttime'];
			$nexttime_str  = ($nexttime>0)?'下次联系：'.YmdHis($nexttime,'YmdHi'):'';
            $pathlist      = $rows['pathlist'];
            $medialist     = $rows['medialist'];
            $crm_ukind = intval($rows['crm_ukind']);
            $crm_ugrade = intval($rows['crm_ugrade']);
            $crm_usjtime1 = intval($rows['crm_usjtime1']);
            $crm_usjtime2 = intval($rows['crm_usjtime2']);
            $gjnum = intval($rows['gjnum']);
			$photo_s_url = (!empty($photo_s))?UP.$photo_s:RES.'photo_s'.$sex.'.png';
			
			$addtime_str = '<b>'.YmdHis($rows['addtime'],'d').'</b>日<br><font>'.YmdHis($rows['addtime'],'Y').'/'.YmdHis($rows['addtime'],'m').'</font>';
			$content = '<em>'.dataIO($rows['content'],'out').'</em>';
			
			//$crm_ugrade=0;
			//$row = $db->ROW(__TBL_USER__,"crm_ugrade","id=".$uid,"name");
			//if ($row)$crm_ugrade = intval($row['crm_ugrade']);
			if ($crm_ugrade<1){
				$intention_str = '售前意向：'.crm_arr_title($bbs_intentionARR,$intention).'<br>';
			}else{
				$intention_str = '';
			}
			
			$crm_vip_title = ($crm_ugrade>0)?crm_ugrade_time($uid,$crm_ugrade,'noAno__',$crm_usjtime1,$crm_usjtime2):'';
			$crm_ukind_title = ($crm_ukind>0)?' '.udata('crm_ukind',$crm_ukind).' ':'';
			$crm_vip_ukind= $crm_vip_title.$crm_ukind_title;
			
            $title2 = (!empty($nickname))?$uid.'<font>|</font>'.urlencode($nickname):$uid;
			?>
            <dl id="tr<?php echo $id;?>">
            	<div class="tbody">
                	<a href="<?php echo mHref('crm_u',$uid);?>"><img class="photo_s" src="<?php echo $photo_s_url;?>"></a>
                	<?php echo uicon($sex.$grade);?><b><?php echo $uid;?></b><font>（<?php echo $truename.$nickname;?>）</font>
					<?php if(ifint($admid))echo '<div class="rtitle">'.$admname.'<font>（ID:'.$admid.'）</font></div>';?>
				</div>
                <dt>
                	<div class="timebox"><?php echo $addtime_str;?><div class="zj"></div></div>
                    <?php
					if ($addtime > 0){
						$bbsday = intval(ADDTIME-$addtime);
						$bbsday = intval($bbsday/86400);
						if($bbsday>0){
							$bbsday_cls = ($bbsday>7)?' Cf00':' C999';
							echo '<div class="addtimetips'.$bbsday_cls.'">'.$bbsday.'天未联系</div>';
						}
					}
					?>
                </dt>
                <dd class="CC">
                	<?php
                    echo $intention_str.$nexttime_str.$content;
                    if(!empty($pathlist)){
                        $ARR=explode(',',$pathlist);
                        echo '<div class="pathlist">';
                        foreach ($ARR as $V) {?>
                            <a href="javascript:;" class="zoom" onClick="parent.parent.ZeaiM.piczoom('<?php echo smb(UP.$V,'b'); ?>');"><img src="<?php echo UP.$V;?>"></a>
                            <?php
                        }
                        echo '</div>';
                    }?>
                    <?php if(CRMQX('gj_mod_update') && ifmyu($uid)){?><a href="javascript:;" photo_s_url=<?php echo $photo_s_url;?> clsid="<?php echo $id;?>" uid="<?php echo $uid;?>" title2="<?php echo $title2;?>" class="editico ico">&#xe610;</a><?php }?>
					<?php if(CRMQX('crm_bbs_del') && ifmyu($uid)){?><a href="crm_gj_yj.php?submitok=gj_del_update&id=<?php echo $id;?>&uid=<?php echo $uid;?>&js=a" onclick="return confirm('确定删除？')" class="delico ico">&#xe779;</a><?php }?>
                    <a href="javascript:;" class="btn size2 zeaibg btn_numtips gjlist" photo_s_url=<?php echo $photo_s_url;?> uid="<?php echo $uid;?>" title2="<?php echo $title2;?>">跟进<?php echo ($gjnum>0)?'<span>'.$gjnum.'</span>':'';?></a>
                </dd>
                <div class="crm_vip_ukind"><?php echo $crm_vip_ukind; ?></div>
                <div class="clear"></div>
            </dl>
			<?php
		}
	}
	?>
</form>
<script>var bg = '<?php echo $_Style['list_bg']; ?>',overbg   = '<?php echo $_Style['list_overbg']; ?>',selectbg = '<?php echo $_Style['list_selectbg']; ?>';</script>
<?php if ($total > 0 ){?>
    <?php
	echo $page_cls;
	if ($total > $pagesize){?>
    <div class="listbottombox" style="text-align:center">
        <?php echo '<div class="pagebox" style="float:initial">'.$pagelist.'</div>'; ?>
    </div>
    <?php }?>
    <div id="backtop"><a id="btmTopBtn"><i class="ico">&#xe60c;</i>顶部</a></div>
    <script>
    document.body.onscroll = backtop_alone;
	zeai.listEach('.editico',function(obj){
		var uid = parseInt(obj.getAttribute("uid")),id=obj.getAttribute("clsid"),
		title2 = obj.getAttribute("title2");
		var photo_s_url = decodeURIComponent(obj.getAttribute("photo_s_url"));
		var photo_s_iframeL = (!zeai.empty(photo_s_url))?'<img src="'+photo_s_url+'" class="photo_s_iframeL">':'';
		obj.onclick=function(){
			ZeaiM.iframe({title:photo_s_iframeL+'<span>【'+title2+'】</span>',url:'crm_gj_yj.php?id='+id+'&uid='+uid+'&submitok=gj_mod',fn:function(){
				setTimeout(function(){location.reload(true);},500);
			}});
		}
	});
	zeai.listEach('.gjlist',function(obj){
		var uid = parseInt(obj.getAttribute("uid")),id=obj.getAttribute("clsid"),
		title2 = obj.getAttribute("title2");
		var photo_s_url = decodeURIComponent(obj.getAttribute("photo_s_url"));
		var photo_s_iframeL = (!zeai.empty(photo_s_url))?'<img src="'+photo_s_url+'" class="photo_s_iframeL">':'';
		obj.onclick=function(){
			ZeaiM.iframe({title:photo_s_iframeL+'<span>【'+title2+'】</span>',url:'crm_gj_yj.php?uid='+uid+'&submitok=gj_list',fn:function(){
				setTimeout(function(){location.reload(true);},500);
			}});
		}
	});
    </script>
    <script src="js/zeai_tablelist.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<?php }?>
</body></html><?php ob_end_flush();?>